#pragma once

#include "Server/ServerType.h"
#include "wch/StringTokenizer.h"
using namespace wch;

struct DBConfig
{
	std::string _name;
	std::string	_host;
	UInt16		_port;
	std::string _user;
	std::string	_passwd;

	DBConfig() : _port( 0 ) {}
};

class Cfg
{
public:
	Cfg();
	bool load(const std::string&);

public:
	inline void setId( UInt32 id )					{ _sid = id;	}
	inline void setTcpPort( UInt16 p )				{ _tcpPort = p;	}
	inline void setDataDatabase( const char * ip, UInt16 port, const char * user, const char * pwd, const char * db )
	{
		_dataConf._host		= ip;
		_dataConf._port		= port;
		_dataConf._user		= user;
		_dataConf._passwd	= pwd;
		_dataConf._name		= db;
	}
	inline void setPlatDatabase( const char * ip, UInt16 port, const char * user, const char * pwd, const char * db )
	{
		_platConf._host		= ip;
		_platConf._port		= port;
		_platConf._user		= user;
		_platConf._passwd	= pwd;
		_platConf._name		= db;
	}
	inline void setObjectDatabase( const char * ip, UInt16 port, const char * user, const char * pwd, const char * db )
	{
		_objectConf._host		= ip;
		_objectConf._port		= port;
		_objectConf._user		= user;
		_objectConf._passwd		= pwd;
		_objectConf._name		= db;
	}

	inline void setHallAddress( const char * ip, UInt16 port )
	{
		_hallIp = ip;
		_hallPort = port;
	}

	void setPlayer1Mjs(const char *);
	void setPlayer2Mjs(const char *);
	void setPlayer3Mjs(const char *);
	void setPlayer4Mjs(const char *);

	inline void setFree(UInt8 free) { _free = free > 0; }
	inline DBConfig getDataConfig() { return _dataConf; }
	inline DBConfig getPlatConfig() { return _platConf; }
	inline DBConfig getObjectConfig() { return _objectConf; }

	inline UInt16 getTcpPort() { return _tcpPort; }

	inline UInt32 getSid()		{ return _sid; }

	inline std::string getHallIp()	{ return _hallIp; }
	inline UInt16 getHallPort()	{ return _hallPort; }

public:
	UInt32	 _sid;
	UInt16	 _tcpPort;
	DBConfig _dataConf;
	DBConfig _platConf;
	DBConfig _objectConf;

	std::string _hallIp;
	UInt16		_hallPort;

private:
	std::string _file;

public:
	std::vector<UInt8> _allotMjs[4];

public:
	bool _free;
};

extern Cfg cfg;